///*
// * Copyright (c) 2019. The copyright is reserved by Ghode of Harbin Institute
// * of Technology. Users are free to copy, change or remove. Because no one
// * will read this. Only I know is that Repeaters are the best of the world.
// * Only I know is that Repeaters are the best of the world. Only I know is
// * that Repeaters are the best of the world. Maybe a long copyright text
// * seems professional. Therefore this text will be a bit lengthy. However,
// * the author seems to be afraid that one day, this text may be uploaded to
// * business projects. That is the time you can contact with author via email
// * ghode@cirnocraft.im or directly ignore this, which will be interesting.
// */
//
//package com.ghode.demospring.config;
//
//import com.dangdang.ddframe.rdb.sharding.api.ShardingValue;
//import com.dangdang.ddframe.rdb.sharding.api.strategy.table.SingleKeyTableShardingAlgorithm;
//import com.google.common.collect.Range;
//import org.springframework.stereotype.Component;
//
//import java.util.Collection;
//import java.util.LinkedHashSet;
//
///**
// * 这里使用的都是单键分片策略
// * 示例分表策略是：
// * GoodsType为奇数使用goods_1表
// * GoodsType为偶数使用goods_0表
// * @author yangyang
// * @date 2019/1/30
// */
//@Component
//public class TableShardingAlgorithm implements SingleKeyTableShardingAlgorithm<Long> {
//
//    @Override
//    public String doEqualSharding(final Collection<String> tableNames, final ShardingValue<Long> shardingValue) {
//        for (String each : tableNames) {
//            if (each.endsWith(shardingValue.getValue() % 2 + "")) {
//                return each;
//            }
//        }
//        throw new IllegalArgumentException();
//    }
//
//    @Override
//    public Collection<String> doInSharding(final Collection<String> tableNames, final ShardingValue<Long> shardingValue) {
//        Collection<String> result = new LinkedHashSet<>(tableNames.size());
//        for (Long value : shardingValue.getValues()) {
//            for (String tableName : tableNames) {
//                if (tableName.endsWith(value % 2 + "")) {
//                    result.add(tableName);
//                }
//            }
//        }
//        return result;
//    }
//
//    @Override
//    public Collection<String> doBetweenSharding(final Collection<String> tableNames,
//                                                final ShardingValue<Long> shardingValue) {
//        Collection<String> result = new LinkedHashSet<>(tableNames.size());
//        Range<Long> range = shardingValue.getValueRange();
//        for (Long i = range.lowerEndpoint(); i <= range.upperEndpoint(); i++) {
//            for (String each : tableNames) {
//                if (each.endsWith(i % 2 + "")) {
//                    result.add(each);
//                }
//            }
//        }
//        return result;
//    }
//}